package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.entity.User;
import org.example.service.UserService;
import org.example.sso.model.entity.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Controller
public class LoginController {

    @Autowired
   private UserService userService;

    @RequestMapping("/toLogin")
    public ModelAndView toLogin(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");
        modelAndView.addObject("userName", "tom");
        log.info("toLogin->" + request.getRequestURI());
        return modelAndView;
    }

    @RequestMapping("/login")
    public @ResponseBody String login(@RequestBody User user) {
        UserDO loginUser = userService.loginByUser(user);
        log.info("login->");
        return "2";
    }

    @RequestMapping("/login2")
    public @ResponseBody String login2(@RequestBody User user) {
        UserDO loginUser = userService.loginByUser(user);
        log.info("login->");
        return "222";
    }
}
